export default {
    namespaced: true,
    state() {
        return {
            // 用户登录凭据
            cookie: JSON.parse(localStorage.getItem('cookie')) || '{}',
            // 用户详情
            userInfo: JSON.parse(localStorage.getItem('userInfo')) || '{}',
            // 用户歌单列表
            userSongList: JSON.parse(localStorage.getItem('user_song_list')) || '{}',
            // 用户喜欢歌单列表
            userSongLoveList:JSON.parse(localStorage.getItem('user_song_love_list')) || '{}',
        }
    },
    mutations: {
        // 持久化存储到本地
        saveCookieTolocalStorage(state) {
            localStorage.setItem("cookie", JSON.stringify(state.cookie))
        },
        saveUserInfoTolocalStorage(state) {
            localStorage.setItem("userInfo", JSON.stringify(state.userInfo))
        },
        saveUserSongListTolocalStorage(state){
            localStorage.setItem("user_song_list", JSON.stringify(state.userSongList))
        },
        saveUserLoveListTolocalStorage(state){
            localStorage.setItem("user_song_love_list", JSON.stringify(state.userSongLoveList))
        },
        // 修改登录凭据
        updatecookie(state, cookie) {
            state.cookie = cookie
            // 保存到本地
            this.commit("m_user/saveCookieTolocalStorage")
        },
        // 修改用户详情
        updateUserInfo(state, userInfo) {
            state.userInfo = userInfo
            this.commit("m_user/saveUserInfoTolocalStorage")
        },
        // 修改歌单列表
        updateSongList(state,songList){
            state.updateSongList = songList
            this.commit("m_user/saveUserSongListTolocalStorage")
        },
        // 修改用户喜欢列表
        updateUserLoveList(state,userSongLoveList){
            state.userSongLoveList = userSongLoveList
            this.commit("m_user/saveUserLoveListTolocalStorage")
        }
    }
}